//
//  TouristsWebController.m
//  EMMApp
//
//  Created by edz on 2019/8/13.
//  Copyright © 2019 YiXun. All rights reserved.
//

#import "TouristsWebController.h"


static NSString *YUQi_weiqianyue =@"appapi/backstage_sign/";
static NSString *YUQi_weifukuan =@"appapi/backstage_receipt/";

@interface TouristsWebController ()
@property (nonatomic,strong) UIWebView *webView;
@property (nonatomic,strong) NSURLRequest *urlRequest;
@end

@implementation TouristsWebController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatNavigationController];
    [self setupUI];
    
}

-(void)setupUI{
    
     self.navigationItem.title = _titleString;
    
    self.webView =[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, EMM_WIDTH, EMM_HEIGHT-SafeAreaTopHeight)];
    [self.view addSubview:self.webView];
    
    NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
    NSString *terminalCode = [IDTools devId2];
    NSString *merchantId = [userdf objectForKey:@"merchantId"];
    NSString *projectId = [userdf objectForKey:@"projectId"];
    NSString *version = apiVString;
    NSString *busNumType = @"11";
    NSString *busNum = @"01";
    NSString *token = [userdf objectForKey:@"is_login"];
    NSString *userId = [userdf objectForKey:@"userNameId"];
    NSString *projectCode = [userdf objectForKey:@"projectCode"];
    
    CustomerModel *paramsModel =[[CustomerModel alloc]init];
    paramsModel.params =[[bodyModel alloc]init];
    paramsModel.params.terminalCode =terminalCode;
    paramsModel.params.merchantId =merchantId;
    paramsModel.params.projectId =projectId;
    paramsModel.params.version =version;
    paramsModel.params.busNumType =busNumType;
    paramsModel.params.busNum =busNum;
    paramsModel.params.token =token;
    paramsModel.params.userId =userId;
    paramsModel.params.projectCode =projectCode;
    NSString *params = [paramsModel toJSONString];
    NSString *UrlStr;
    if (self.TouristType ==None_QianYue) {
        UrlStr =[NSString stringWithFormat:@"%@/%@?body=%@",apiBaseUrl,YUQi_weiqianyue,params];
    }else if(self.TouristType == None_FuKuan){
        UrlStr =[NSString stringWithFormat:@"%@/%@?body=%@",apiBaseUrl,YUQi_weifukuan,params];
    }
    
    NSString *destionURL = [UrlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *URL =[NSURL URLWithString:destionURL];
    [self.webView loadRequest:[NSURLRequest requestWithURL:URL]];
    self.urlRequest = [NSURLRequest requestWithURL:URL];
}

- (void)creatNavigationController {
    [self updateNavBar];
    
    //返回按钮初始化
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setFrame:CGRectMake(0, 0, 54 ,44)];
    [backBtn addTarget:self
                action:@selector(backToPreviousPage:)
      forControlEvents:UIControlEventTouchUpInside];
    [backBtn setBackgroundColor:[UIColor clearColor]];
    [backBtn setImage:[UIImage imageNamed:@"ico_back"] forState:UIControlStateNormal];
    backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    if (EMM_WIDTH <= 320) {
        backBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
    }else if (EMM_WIDTH > 375){
        backBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
    }else{
        backBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
    }
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
}

- (void)backToPreviousPage:(id)send {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
